package pharao.client.views.game.landkarte.ort.tutorium;

import pharao.client.i18ln.GuiText;
import pharao.client.views.game.landkarte.ort.basics.events.ShowOrtBasicViewEvent;

import com.google.gwt.user.client.ui.ClickListener;
import com.google.gwt.user.client.ui.Hyperlink;
import com.google.gwt.user.client.ui.Image;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.VerticalPanel;
import com.google.gwt.user.client.ui.Widget;

import hmvc4gwt.client.event.IHmvcEvent;
import hmvc4gwt.framework.client.events.CloseViewEvent;
import hmvc4gwt.framework.client.events.ResetViewEvent;
import hmvc4gwt.framework.client.view.GuiView;

public class TutoriumView extends GuiView {
	
	private Hyperlink hyperlinkBack				= new Hyperlink(GuiText.constants.link_back(), null);
	private Hyperlink hyperlinkBackToMenu		= new Hyperlink(GuiText.constants.link_back(), null);
	
	private Hyperlink hyperlinkAddition 		= new Hyperlink(GuiText.constants.link_game_ort_basics_addition(), null);
	private Hyperlink hyperlinkSubtraktion 		= new Hyperlink(GuiText.constants.link_game_ort_basics_subtraktion(), null);
	private Hyperlink hyperlinkMultiplikation	= new Hyperlink(GuiText.constants.link_game_ort_basics_multiplikation(), null);
	private Hyperlink hyperlinkDivision 		= new Hyperlink(GuiText.constants.link_game_ort_basics_divisison(), null);
	
	private VerticalPanel menuPanel = new VerticalPanel();
	
	//TODO il8n!!
	private Label labelTitel = new Label("Hier lernst du alles über Addition, Subtraktion Multiplikation und Division.");

	public void initImpl() {
		
		ClickListener listener = new ClickListener() {
			public void onClick(Widget sender) {
				handleHyperlinkAction(sender);
			}
		};
		
		hyperlinkAddition.addClickListener(listener);
		hyperlinkSubtraktion.addClickListener(listener);
		hyperlinkMultiplikation.addClickListener(listener);
		hyperlinkDivision.addClickListener(listener);
		hyperlinkBack.addClickListener(listener);
		hyperlinkBackToMenu.addClickListener(listener);
		
		
		menuPanel.setStylePrimaryName("gameMenu");
		
		menuPanel.add(hyperlinkAddition);
		menuPanel.add(hyperlinkSubtraktion);
		menuPanel.add(hyperlinkMultiplikation);
		menuPanel.add(hyperlinkDivision);
		
		showMenu();
		
	}

	private void showMenu() {
		clear();
		add(labelTitel);
		add(hyperlinkBack);
		add(menuPanel);
	}
	
	public void terminate() {
		// TODO Auto-generated method stub

	}

	public void handleEventImpl(IHmvcEvent event) {
		// TODO Auto-generated method stub

	}
	
	private void handleHyperlinkAction(Widget sender) {
		
		remove(menuPanel);
		
		if (sender == hyperlinkAddition) {
			showTutoriumAdditon();
		} else if (sender == hyperlinkSubtraktion) {
			showTutoriumSubtraktion();
		} else if (sender == hyperlinkMultiplikation) {
			showTutoriumMultiplikation();
		} else if (sender == hyperlinkDivision) {
			showTutoriumDivision();
		} else if (sender == hyperlinkBack) {
			getController().fireEventLocal(new CloseViewEvent());
			getController().fireEventLocal(new ResetViewEvent());
			getController().fireEvent(new ShowOrtBasicViewEvent(), true, false, false);
		} else if (sender == hyperlinkBackToMenu) {
			showMenu();
		}
		
	}

	protected void resetView() {
		showMenu();
	}
	
	private void showTutoriumDivision() {
		// TODO Auto-generated method stub
		
	}

	private void showTutoriumMultiplikation() {
		// TODO Auto-generated method stub
		
	}

	private void showTutoriumSubtraktion() {
		// TODO Auto-generated method stub
		
	}

	private void showTutoriumAdditon() {
		
		Tutorium tutorium = new Tutorium("Addition");
		
		Label label1 = new Label("Seite 1 - Die Addition ist die wohl einfachste aller Mathematische Grund-Rechenarten.");
		Image image1 = new Image("images/landkarte/ort/basics/tutorium/tutorium_1.jpg");
		
		tutorium.addPage(label1, image1);
		
		Label label2 = new Label("Seite 2 - Die Addition ist die wohl einfachste aller Mathematische Grund-Rechenarten.");
		Image image2 = new Image("images/landkarte/ort/basics/tutorium/tutorium_1.jpg");
		
		tutorium.addPage(label2, image2);
		
		Label label3 = new Label("Seite 3 - Die Addition ist die wohl einfachste aller Mathematische Grund-Rechenarten.");
		Image image3 = new Image("images/landkarte/ort/basics/tutorium/tutorium_1.jpg");
		
		tutorium.addPage(label3, image3);
		
		tutorium.startTutorium();
		
		clear();
		add(hyperlinkBackToMenu);
		add(tutorium.getWidget());
	}
}
